FROM node:16 as builder
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

WORKDIR /app
# 提前安装依赖， 避免每次安装依赖花很久时间
# 只要 package.json 不修改就会用 docker cache
COPY package.json /app
COPY pnpm-lock.yaml /app
RUN pnpm install --registry=https://registry.npmmirror.com

ADD . /app
RUN pnpm build

FROM nginx
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx/default.conf /etc/nginx/conf.d
